package com.atguigu.juc.java8基础;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 题目：请按照给出数据，找出同时满足以下条件的用户。也即以下条件全部满足
 * 偶数Id且年龄大于25且用户名转为大写字母倒排序
 * 只输出一个用户名字
 */
public class StreamDemo {

    public static void main(String[] args) {

        User u1 = new User("aa", 11, 23);
        User u2 = new User("bb", 12, 24);
        User u3 = new User("cc", 13, 25);
        User u4 = new User("dd", 14, 26);
        User u5 = new User("ee", 15, 27);
        User u6 = new User("ff", 16, 28);

        List<User> list = Arrays.asList(u1, u2, u3, u4, u5, u6);

        list.stream().filter(u -> {
            return ((u.getId() % 2) == 0);
        }).filter(u -> {
            return (u.getAge() > 24);
        }).map(m -> {
            return m.getUserName().toUpperCase();
        }).sorted((o1, o2) -> {
            return o2.compareTo(o1);
        }).limit(1).forEach(System.out::println);


//        List<Integer> list2 = Arrays.asList(1,2,3);
//        list2 = list2.stream().map(x -> {return x * 2;}).collect(Collectors.toList());
//        list2.forEach(System.out::println);

        /**
         *  函数核心四大接口 见脑图
         *
         * Function<String,Integer> function = s -> {return s.length();};
         *         System.out.println(function.apply("abc"));
         *
         *         Predicate<String> predicate = s -> {
         *              return s.equals("abc");
         *
         *         };
         *         System.out.println(predicate.test("abc"));
         */


    }

}
